package com.zh.api.controller.servicer;

import com.zh.common.utils.MD5Utils;
import com.zh.common.utils.PageUtils;
import com.zh.common.utils.Query;
import com.zh.common.utils.ResultVO;
import com.zh.servicer.domain.ServiceDO;
import com.zh.servicer.service.ServiceService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * Created by caogang on 2019/5/28.
 */

@Controller
@RequestMapping("/servicer/servicerStaff")
@Api("服务商人员管理")
public class ServicerStaffController {


     @Autowired
     private ServiceService serviceService;


    @ResponseBody
    @GetMapping("/list")
    @ApiOperation("获取服务商人员列表")
    public PageUtils serviceList(@RequestParam Map<String, Object> params){
        //查询列表数据
        Query query = new Query(params);
        List<ServiceDO> serviceList = serviceService.list(query);
        int total = serviceService.count(query);
        PageUtils pageUtils = new PageUtils(serviceList, total);
        return pageUtils;
    }

    /**
     *保存服务商人员
     */
    @ResponseBody
    @PostMapping("/save")
    @ApiOperation("保存服务商人员")
    public ResultVO save(ServiceDO service){
        if(serviceService.save(service)>0){
            return ResultVO.success();
        }
        return ResultVO.error();
    }

    /**
     * 根据服务商人员id获取服务商人员信息
     * @param userId
     * @param model
     * @return
     */
    @ResponseBody
    @PostMapping( "/getServicerStaffInfo")
    @ApiOperation("根据服务商人员id获取服务商人员信息")
    ResultVO  getServicerStaffInfo(String userId){
        ServiceDO  serviceDO = serviceService.get(userId);
        Map map =new HashMap();
        map.put("serviceDO",serviceDO);
        return  ResultVO.success(map);
    }


    /**
     * 修改服务商人员
     * @param service
     * @return
     */
    @ResponseBody
    @RequestMapping("/update")
    @ApiOperation("修改服务商人员")
    public ResultVO update(ServiceDO service){
        if(serviceService.update(service)>0){
            return  ResultVO.success();
        }
        return ResultVO.error();
    }


    /**
     * 删除服务商人员
     * @param userId
     * @return
     */
    @ResponseBody
    @PostMapping( "/remove")
    @ApiOperation("删除服务商人员")
    public ResultVO remove( String userId){
        if(serviceService.remove(userId)>0){
            return ResultVO.success();
        }
            return ResultVO.error();
    }


    /**
     * 批量删除服务商人员
     * @param userId
     * @return
     */
    @ResponseBody
    @PostMapping( "/batchRemove")
    @ApiOperation("批量删除服务商人员")
    public ResultVO batchRemove(@RequestParam("ids[]") String[] userIds){
        if(serviceService.batchRemove(userIds)>0){
            return ResultVO.success();
        }
             return ResultVO.error();
    }


}
